package com.oocl.homework.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.oocl.homework.dao.AreasDao;
import com.oocl.homework.pojo.Areas;
import com.oocl.homework.util.DBUtil;

public class AreasDaoImpl implements AreasDao{

	@Override
	public List<Areas> getAreas(String area) {
		String sql = "select * from areas where area like '%"+area+"%'";
		List<Areas> list=new ArrayList<Areas>();
		Connection con=DBUtil.createConnection();
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {
			pst=con.prepareStatement(sql);
			rs=pst.executeQuery();
			while (rs.next()) {
				Areas a=new Areas(rs.getString("areaid"),rs.getString("area"), rs.getString("cityid"));
				list.add(a);				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		DBUtil.close(con, pst, rs);
		return list;
	}

}
